package springboot.service.impl;

import org.springframework.stereotype.Service;
import springboot.dao.WxGroupUserDao;
import springboot.doMain.WxGroupUser;
import springboot.service.WXGroupUserService;

import java.util.ArrayList;
import java.util.List;

@Service
public class WXGroupUserServiceImpl implements WXGroupUserService {
	
	final
	WxGroupUserDao wxGroupUserDao;
	
	public WXGroupUserServiceImpl(WxGroupUserDao wxGroupUserDao) {
		this.wxGroupUserDao = wxGroupUserDao;
	}
	
	@Override
	public int deleteByPrimaryKey(Long id) {
		return 0;
	}
	
	@Override
	public int insert(WxGroupUser record) {
		List<WxGroupUser> wxGroupUsers = selGroupUser(record);
		if (wxGroupUsers.isEmpty()) {
			return wxGroupUserDao.insert(record);
		} else if (wxGroupUsers.size() == 1) {
			if (wxGroupUserDao.updateGroupUser(record) == 1) {
				return 3;
			}
			return -3;
		} else {
			for (int i = 1; i < wxGroupUsers.size(); i++) {
				WxGroupUser wxGroupUser = wxGroupUsers.get(i);
				wxGroupUserDao.deleteByChatIdAndUserId(wxGroupUser);
			}
			return 4;
		}
		
	}
	
	
	@Override
	public List<WxGroupUser> selAllExternalUser() {
		return wxGroupUserDao.selAllExternalUser();
	}
	
	
	@Override
	public List<WxGroupUser> selGroupUser(WxGroupUser wxGroupUser) {
		return wxGroupUserDao.selGroupUser(wxGroupUser);
	}
	
	@Override
	public int deleteByChatIdAndUserId(WxGroupUser wxGroupUser) {
		return wxGroupUserDao.deleteByChatIdAndUserId(wxGroupUser);
	}
	
	@Override
	public int insertSelective(WxGroupUser record) {
		return 0;
	}
	
	@Override
	public int updateGroupUser(WxGroupUser record) {
		return wxGroupUserDao.updateGroupUser(record);
	}
	
	
	@Override
	public int updateByPrimaryKey(WxGroupUser record) {
		return 0;
	}
}
